package com.jing.shop.controller;

import com.github.pagehelper.PageInfo;
import com.jing.common.core.domain.R;
import com.jing.shop.domain.Result;
import com.jing.shop.domain.dto.ProductTypeDTO;
import com.jing.shop.domain.po.ProductTypePO;
import com.jing.shop.domain.vo.ProductShopTypeVO;
import com.jing.shop.domain.vo.ProductTypeVO;
import com.jing.shop.service.ProductTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "商品分类")
@RestController
@RequestMapping("/type")
public class ProductTypeController {

    private static final Logger log = LoggerFactory.getLogger(ProductAttributeCategoryController.class);

    @Autowired
    private ProductTypeService productTypeService;

    @ApiOperation("商品分类列表")
    @PostMapping("/page")
    public R page(@RequestBody ProductTypeDTO productTypeDTO){
        PageInfo<ProductTypeVO> typeList = productTypeService.findTypeList(productTypeDTO);
        return R.ok(typeList,"列表");
    }

    @ApiOperation("商品分类添加")
    @PostMapping("/add")
    public R add(@RequestBody ProductTypeDTO productTypeDTO){
        productTypeService.addType(productTypeDTO);
        return R.ok("添加成功");
    }

    @ApiOperation("商品分类修改")
    @PostMapping("/update")
    public R update(@RequestBody ProductTypeDTO productTypeDTO){
        productTypeService.updateType(productTypeDTO);
        return R.ok("修改成功");
    }

    @ApiOperation("商品分类删除")
    @PostMapping("/del/typeId")
    public R del(@PathVariable Integer typeId){
        productTypeService.delTypeId(typeId);
        return R.ok("删除成功");
    }

    @ApiOperation("分类")
    @GetMapping("/findList")
    public R findList(){
        List<ProductTypeVO> list = productTypeService.findList();
        return R.ok(list,"分类查询成功");
    }

    @ApiOperation("修改导航栏状态")
    @PostMapping("/updatetypeNavigation")
    public R updatetypeNavigation(@RequestBody ProductTypeDTO productTypeDTO){
        productTypeService.updatetypeNavigation(productTypeDTO);
        return R.ok("修改导航栏状态成功");
    }

    @ApiOperation("商品品牌列表展示")
    @PostMapping("/updatetypeDisplay")
    public R updatetypeDisplay(@RequestBody ProductTypeDTO productTypeDTO){
        productTypeService.updatetypeDisplay(productTypeDTO);
        return R.ok("修改显示状态成功");
    }

    @ApiOperation("上传图片")
    @PostMapping("/upload")
    public R upload(@RequestParam("file") MultipartFile multipartFile){
        R upload = productTypeService.upload(multipartFile);
        return upload;
    }

    @ApiOperation("递归")
    @GetMapping("/diGui/{typeLevel}")
    public R<ArrayList<ProductShopTypeVO>> diGui(@PathVariable Integer typeLevel){
        ArrayList<ProductShopTypeVO> productShopTypeVOS = productTypeService.diGui(typeLevel);
        return R.ok(productShopTypeVOS);
    }

}
